package yingyong;

import Studentlei.xuesheng;
import gongju.DBUtil;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

@WebServlet("/select")
public class select extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf8");
        response.setContentType("text/html;charset=utf8");
        String sql = "SELECT aid,s.sid,s.sname,time,type FROM attence a , student s WHERE a.sid=s.sid";
        ArrayList<xuesheng> list = new ArrayList<>();
        try {
            Connection conn = DBUtil.getcoon();
            PreparedStatement pre = conn.prepareStatement(sql);
            ResultSet re = pre.executeQuery();
            while (re.next()) {
                int aid = re.getInt("aid");
                int sid = re.getInt("sid");
                String sname = re.getString("sname");
                String time = re.getString("time");
                int type = re.getInt("type");
                xuesheng xs = new xuesheng(aid, sid, sname, time, type);
                list.add(xs);
                }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } finally {
        }
        request.setAttribute("list",list);
        request.getRequestDispatcher("WEB-INF/jiemian.jsp").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
